package com.example.demo.Util;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
public class FeishuiUtil {
    @Value("${Feishui.url}")
    private static String BASE_URL ;
    // 利用Webhook发送信息到飞书机器人，实时报错
    public static void post(String msg){
        ThreadPoolUtil.execute(() -> {String json = "{\"msg_type\": \"text\",\"content\": {\"text\": \""+msg+"\"}}";
            StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
            HttpPost httpPost = new HttpPost(BASE_URL);
            httpPost.setEntity(entity);
            httpPost.setHeader("Content-Type", "application/json");
            try {
                HttpClients.createDefault().execute(httpPost);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });};
}

